from bs4 import BeautifulSoup
from tools import *
from concurrent.futures import ThreadPoolExecutor


pool = ThreadPoolExecutor(128)


def get_img_urls(page_url):
    host = 'https://bing.ioliu.cn'
    response = requests.get(page_url)
    soup = BeautifulSoup(response.content.decode(response.encoding))
    imgs = soup.select('.download')
    return list(host+u.get('href') for u in imgs)


def download():
    import time
    for i in range(76):
        for u in get_img_urls(f'https://bing.ioliu.cn/ranking?p={i+1}'):
            pool.submit(write_file, get_image_bytes(u), f'../images/{time.time()}.png')


if __name__ == '__main__':
    download()
